function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}
var i = t(require("../../config/config"));
//var o = require("../../config/tabs");
//var d = getApp();
var app = getApp();


Page({
    data: {
		isSpread: !0,
		'activeTab': 0,
		'scrollLeft': 0,
		activeSiteIndex: -1,
		preTappedMarkerID: -1,
		imgUrl: '',
		//地图start
		//当前位置，也就是标志的位置
		iconPathed: '/resources/icon_attraction_selected@2x.png',//选中
		iconPath: '/resources/icon_attraction@2x.png',//没有选中
		markers: [],
		//其他位置


		//地图end
		activeSiteList: [],
    },
	
    onLoad: function(t) {
		var me = this;
		try {
			me.setData({
				imgUrl:wx.getStorageSync('url')
			});
		}catch (e) {
				  
		}
		me.storeType();
    },
	//根据ajax返回的值将图片的返回http://url地址
	getImgUrl: function (url) {
		var me = this;					
		return wx.getStorageSync('url')+url;
	},
	//地图start
	
	
	//点击标识
	markerTapped: function(t) {
		var me = this;
        var e = this.data.isSpread, a = (this.data.preTappedMarkerID, t.markerId);
		var activeSiteList = me.data.activeSiteList;
		for (var i in activeSiteList)
		{
			if (activeSiteList[i]['id'] == a)
			{
				me.updateMarkersColorByID(i);
				break;
			}
		};
		me.setData({
			'scrollLeft':110
		});
    },

	//地图end
    //获得分类
    storeType: function (){
		var me = this;
		app.util.request({
			url: "entry/wxapp/StoreTypely",
			cachetime: "0",
			data: {
			},
			success: function (a) {
				var data = a.data;
				me.setData({
					tabs: data
				});
				for (var i in data)
				{
					//console.log(data[i]['id']);
					//初始化第一个分类
					me.resetMarkers(data[i]['id']);
					break;
				}
			}
		});
    },

	//点击导航
   switchTab: function(t) {
        var e = t.currentTarget.dataset.index;
		var i = this.data.activeTab;
		if (e != i)
		{
			this.setData({
				scrollLeft: 0,
				activeSiteIndex: -1,
				preTappedMarkerID: -1
			});
			console.log(e);
			this.resetMarkers(e)
		}
    },
	//获得分类所有列表t当前分类id
	resetMarkers: function(t) {
		var me = this;
		this.setData({
				activeTab: t,
		});
		app.util.request({
			url: "entry/wxapp/typeStoreListly",
			cachetime: "0",
			data: {
				'category': t 
			},
			success: function (a) {
				//默认的哪一个地址
				me.setData({
					"mapCenter.longitude": a.data.default.longitude,
					"mapCenter.latitude": a.data.default.latitude,
				});
				//地图标识
				me.setData({
					"markers": a.data.markers,
					'activeSiteList': a.data.list
				});
				console.log(me.data.mapCenter);
			}
		});
    },
    onShareAppMessage: function() {
        
    },
	//上下点击start
	toggleSpread: function(t) {
        var e = this.data.isSpread;
        this.setData({
            isSpread: !e
        });
    },
	
	//上下点击end
	//滑动效果start
	bindSiteListScroll: function(t) {
        var e = app.util.rpx2px(350);
		var a = app.util.rpx2px(50);
		
		var o = t.detail.scrollLeft;
		var n = Math.floor((o + e) / (e + a));//计算是是滑动到第几张图
		console.log(e);
		//return false;
        this.data.activeSiteIndex !== n && this.updateMarkersColorByIndex(n);
    },
	updateMarkersColorByIndex: function(t) {
        var e = this.data.markers;
        if (e && 0 !== e.length) {
            this.setData({
                activeSiteIndex: t
            });
			//console.log(this.data.activeSiteList);
            this.updateMarkersColorByID(t);
        }
    },
	updateMarkersColorByID: function (i) {
		var me = this;
		var markers = me.data.markers;		
		var activeSite = me.data.activeSiteList[i];
		for (var s in markers)
		{
			console.log(activeSite['id']);
			if (markers[s]['id'] == activeSite['id'])
			{
				markers[s]['iconPath'] = me.data.iconPathed;
			}else{
				markers[s]['iconPath'] = me.data.iconPath;
			}
		}
		me.setData({
			'markers': markers
		});
		console.log(markers);
	}
});